using System;
using System.IO;
using Microsoft.OpenApi.Models;
using System.Reflection;
using DapperDemo.Repository;
using DapperDemo.Repository.IRepo;
using DapperDemo.Repository.Repo;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.DependencyInjection;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(option =>
{
    var xmlPath = Path.Combine(AppContext.BaseDirectory, $"{Assembly.GetExecutingAssembly().GetName().Name}.xml");
    option.IncludeXmlComments(xmlPath, true);
    option.SwaggerDoc("v1", new OpenApiInfo
    {
        Title = $"{Assembly.GetExecutingAssembly().GetName().Name}接口文档",
        Version = "v1.0"
    });
});


builder.Services.AddSingleton<Db>();
builder.Services.AddScoped<ICompanyRepo, CompanyRepo>();

// //SQL Server
// builder.Services.AddDbContext<SchoolContext>(opt =>
//      opt.UseSqlServer(builder.Configuration.GetConnectionString("Default") ?? throw new("数据库连接失败")));

var app = builder.Build();
app.UseSwagger();
app.UseSwaggerUI();
app.MapControllers();
app.Run();